﻿using System;
using System.Linq;
using System.Collections.Generic;
using BusinessNews;
using ServiceNews.DataTransferObjectMapper;

//@@0
namespace NewsService.DataTransferObjectMapper
{
    /// <summary>
    /// Maps DTOs (Data Transfer Objects) to BOs (Business Objects) and vice versa.
    /// </summary>
    public static class Mapper
    {

        #region NewsLog
        /// <summary>
        /// Froms the data transfer object.
        /// </summary>
        /// <param name="obj">The object.</param>
        /// <returns></returns>
        public static NewsLog FromDataTransferObject(NewsLogDto obj)
        {
            if (obj == null) return null;
            return new NewsLog
            {
                Id = obj.Id,
                Title = obj.Title,
                Content = obj.Content,
                Ip = obj.IP,
                Location = obj.Location,
                Device = obj.Device,
                CreatedBy = obj.CreatedBy,
                CreatedDate = obj.CreatedDate,
                Type = obj.Type,
            };
        }
        /// <summary>
        /// To the data transfer object.
        /// </summary>
        /// <param name="obj">The object.</param>
        /// <returns></returns>
        public static NewsLogDto ToDataTransferObject(NewsLog obj)
        {
            if (obj == null) return null;
            return new NewsLogDto
            {
                Id = obj.Id,
                Title = obj.Title,
                Content = obj.Content,
                IP = obj.Ip,
                Location = obj.Location,
                Device = obj.Device,
                CreatedBy = obj.CreatedBy,
                CreatedDate = obj.CreatedDate,
                Type = obj.Type,
            };
        }
        /// <summary>
        /// To the data transfer objects.
        /// </summary>
        /// <param name="objs">The objs.</param>
        /// <returns></returns>
        public static IList<NewsLogDto> ToDataTransferObjects(IEnumerable<NewsLog> objs)
        {
            return objs == null ? null : objs.Select(x => ToDataTransferObject((x))).ToList();
        }
        #endregion

        //@@1
    }
}
